package com.web.config;

import com.alibaba.fastjson.JSONObject;
import com.web.accumulate.entity.AccumulateTransaction;
import com.web.position.entity.Position;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@Configuration
public class RabbitConfig {

    @Bean
    public Queue Queue() {
        return new Queue("coreDirectQueue");
    }

    @Bean
    public Queue Queue2() {
        return new Queue("accumulatedDirectQueue");
    }

	@Autowired
	private AmqpTemplate rabbitTemplate;

	public void sendCore(Position position) {
		String context = JSONObject.toJSONString(position);
		System.out.println("Sender : " + context);
		this.rabbitTemplate.convertAndSend("coreDirectQueue", context);
	}
	public void sendAccumulated(AccumulateTransaction accumulateTransaction) {
		String context = JSONObject.toJSONString(accumulateTransaction);
		System.out.println("Sender : " + context);
		this.rabbitTemplate.convertAndSend("accumulatedDirectQueue", context);
	}

}


